<?php
if (!empty($setmodules))
{
	$module['GENERAL']['CONFIGURATION'] = basename(__FILE__) .'?mode=config';
	return;
}
require('./pagestart.php');

require(INC_DIR .'functions_selects.php');

$mode = isset($_GET['mode']) ? $_GET['mode'] : '';

$return_links = array(
	'index' => '<br /><br />'. sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'),
	'config' => '<br /><br />'. sprintf($lang['CLICK_RETURN_CONFIG'], '<a href="admin_board.php?mode=config">', '</a>')
);

$sql = "SELECT * FROM " . TS_CONFIG;
if (!$result = DB()->sql_query($sql))
{
	ts_die('Could not query config information in admin_board');
}
else
{
	while ($row = DB()->sql_fetchrow($result))
	{
		$config_name = $row['config_name'];
		$config_value = $row['config_value'];
		$default_config[$config_name] = $config_value;
		
		$new[$config_name] = isset($_POST[$config_name]) ? $_POST[$config_name] : $default_config[$config_name];
		
		if (isset($_POST['submit']) && $row['config_value'] != $new[$config_name])
		{
			if ($config_name == 'seed_bonus_points' || $config_name == 'seed_bonus_release' || $config_name == 'bonus_upload' || $config_name == 'bonus_upload_price') $new[$config_name] = serialize(str_replace(',', '.', $new[$config_name]));
			ts_update_config(array($config_name => $new[$config_name]));
		}
	}
	if (isset($_POST['submit']))
	{
		ts_die($lang['CONFIG_UPDATED'] . $return_links[$mode] . $return_links['index']);
	}
}

switch ($mode)
{
	case 'config':
		$template->assign_vars(array(
			'S_CONFIG_ACTION'         => 'admin_board.php?mode=config',
			'CONFIG'             	  => true,
			
			'GENDER'                  => $new['gender'],
			'SITENAME'                => htmlCHR($new['sitename']),
			'CONFIG_SITE_DESCRIPTION' => htmlCHR($new['site_desc']),
			'TIMEZONE_SELECT'         => tz_select($new['board_timezone'], 'board_timezone'),
			'DEFAULT_DATEFORMAT'      => $new['default_dateformat'],
			'ALLOW_AUTOLOGIN'         => ($new['allow_autologin']) ? true : false,
			'DISABLE_BOARD'           => ($new['board_disable']) ? true : false,
			'BIRTHDAY_ENABLED'        => $new['birthday_enabled'],
			'BIRTHDAY_MAX_AGE'        => $new['birthday_max_age'],
			'BIRTHDAY_MIN_AGE'        => $new['birthday_min_age'],
			'BIRTHDAY_CHECK_DAY'      => $new['birthday_check_day'],
			'MAX_LOGIN_ATTEMPTS'      => $new['max_login_attempts'],
			'LOGIN_RESET_TIME'        => $new['login_reset_time'],
			'AUTOLOGIN_TIME'          => (int) $new['max_autologin_time'],
			'SMILIES_PATH'            => $new['smilies_path'],
			'ALLOW_BBCODE'            => ($new['allow_bbcode']) ? true : false,
			'ALLOW_SMILIES'           => ($new['allow_smilies']) ? true : false,
			
		));
		break;
}

print_page('admin_board.tmpl', 'admin');